package com.lagou.edu.controller;

import com.lagou.edu.pojo.Resume;
import com.lagou.edu.service.ResumeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("/resume")
public class ResumeController {

    /**
     * Spring容器和SpringMVC容器是有层次的（父子容器）
     * Spring容器：service对象+dao对象
     * SpringMVC容器：controller对象，，，，可以引用到Spring容器中的对象
     */
    @Autowired
    private ResumeService resumeService;

    @RequestMapping("/list")
    public String queryAll(Model model) throws Exception {
        Page<Resume> resumes = resumeService.queryResumeList();
        model.addAttribute("resumes", resumes.getContent());
        return "list";
    }

    @RequestMapping("/update")
    public String query(Model model, Long id) throws Exception {
        Resume resume = resumeService.queryResumeById(id);
        model.addAttribute("resume",resume);
        return "update";
    }

    @RequestMapping("/add")
    public String add() throws Exception {
        return "update";
    }


    @RequestMapping("/save")
    public String add(Resume resume) throws Exception {
        resumeService.saveOrUdpate(resume);
        return "redirect:/resume/list";
    }

    @RequestMapping("/delete")
    public String delete(Long id) throws Exception {
        resumeService.deleteById(id);
        return "redirect:/resume/list";
    }

}
